﻿
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web;

namespace Lib.Utilities
{
    public class LibForm
    {
        /// <summary>
        /// Lọc thông tin lỗi có cấu trúc dạng loi: Nội dung lỗi :loi
        /// </summary>
        /// <param name="error">Nọi dung chuỗi cần lặp</param>
        public static string GetError(string error)
        {

            error = Until.NVL(error);
            if (error != "")
            {
                error = error.Replace("\r", "").Replace("\n", "").Replace("'", "");
                int index = error.IndexOf("loi:");
                int num2 = error.IndexOf(":loi");
                if ((index != -1) && (num2 > (index + 4)))
                {
                    error = error.Substring(index + 4, (num2 - index) - 4);
                }
                error = "loi:" + error + ":loi";
            }
            return error;
        }
        /// <summary>
        /// Kiểm tra xem tên controk trong mot vùng control nào đó có phải là control hay không
        /// </summary>
        /// <param name="form">Vùng có chưa control</param>
        /// <param name="nameOfControl">Tên control cần kiểm tra</param>
        public static bool IsControl(Control form, string nameOfControl)
        {
            nameOfControl = Until.NVL(nameOfControl).ToUpper();
            if ((nameOfControl != "") && (Until.NVL(form.ID).ToUpper() != nameOfControl))
            {
                for (int i = 0; i < form.Controls.Count; i++)
                {
                    Control control = form.Controls[i];
                    if (Until.NVL(control.ID).ToUpper() == nameOfControl)
                    {
                        return true;
                    }
                    if ((control.Controls.Count > 0) && IsControl(control, nameOfControl))
                    {
                        return true;
                    }
                }
            }
            return false;
        }

        /// <summary>
        /// Tìm control trong một vùng cho trước
        /// </summary>
        /// <param name="form">Vùng chứa control cần tìm</param>
        /// <param name="nameOfControl">Tên control cần tìm</param>
        public static Control FindControl(Control form, string nameOfControl)
        {
            if (form != null)
            {
                nameOfControl = Until.NVL(nameOfControl).ToUpper();
                if ((nameOfControl == "") || (Until.NVL(form.ID).ToUpper() == nameOfControl))
                {
                    return null;
                }
                for (int i = 0; i < form.Controls.Count; i++)
                {
                    Control control = form.Controls[i];
                    if (Until.NVL(control.ID).ToUpper() == nameOfControl)
                    {
                        return control;
                    }
                    if (control.Controls.Count != 0)
                    {
                        Control control2 = FindControl(control, nameOfControl);
                        if (control2 != null)
                        {
                            return control2;
                        }
                    }
                }
            }
            return null;
        }
        /*
        //Đóng một trang
        public static void ClosePage(Page page)
        {
            ClosePage(page, page.Title);
        }

        public static void ClosePage(Page page, object[] a_obj)
        {
            string str;
            string str2;
            P_GOI(b_f, out str, out str2);
            if (str != "")
            {
                se.P_LUU(str, str2, a_obj);
            }
            P_DONG(b_f, b_f.Title);
        }
       
        public static void ClosePage(Page form, string name)
        {
            name = Until.NVL(name);
            if (name != "")
            {
                string str2;
                string str = "";
                string[] strArray = HttpContext.Current.Session["trang"] as string[];
                if (strArray != null)
                {
                    for (int i = 0; i < strArray.Length; i++)
                    {
                        if (strArray[i].IndexOf(name + ",") == 0)
                        {
                            string Result=Until.RemoveElement(strArray, i);
                            HttpContext.Current.Session["trang"] = strArray;
                            break;
                        }
                    }
                    for (int j = 0; j < strArray.Length; j++)
                    {
                        str2 = strArray[j].Split(new char[] { ',' })[0];
                        kytu.P_CONG(ref str, str2);
                    }
                }
                str2 = "form_P_DONG('" + b_ten + "',null);";
                b_f.ClientScript.RegisterClientScriptBlock(b_f.GetType(), "goi_dong", str2, true);
            }
        }
        
        public static void P_DROP_BANG(DR_nhap b_drop, DataTable b_dt)
        {
            b_drop.DataSource = b_dt;
            b_drop.DataBind();
        }


        public static void P_DROP_BANG(DR_nhap b_drop, DataTable b_dt, string b_gtri)
        {
            b_drop.DataSource = b_dt;
            b_drop.DataBind();
            b_drop.SelectedValue = b_gtri;
        }

        public static void P_GIUA(Page b_f, string b_kthuoc)
        {
            if (b_kthuoc != "")
            {
                b_f.ClientScript.RegisterClientScriptBlock(b_f.GetType(), "kthuoc", "resizeTo(" + b_kthuoc + ");", true);
            }
        }

        public static void P_GOI(Page b_f, out string b_tkhao, out string b_dtuong)
        {
            b_tkhao = b_dtuong = "";
            string str = b_f.Title + ",";
            string[] strArray = HttpContext.Current.Session["trang"] as string[];
            if (strArray != null)
            {
                for (int i = 0; i < strArray.Length; i++)
                {
                    if (strArray[i].IndexOf(str) == 0)
                    {
                        b_tkhao = strArray[i].Substring(str.Length);
                        break;
                    }
                }
            }
            int index = b_tkhao.IndexOf(",");
            if (index == 0)
            {
                b_tkhao = "";
            }
            else if (index > -1)
            {
                b_dtuong = b_tkhao.Substring(index + 1);
                b_tkhao = b_tkhao.Substring(0, index);
            }
        }

        /*
           public static void P_GTRI_TEXT(Control b_ctr, string b_gtri)
           {
               if (b_ctr != null)
               {
                   if (b_ctr is ma)
                   {
                       (b_ctr as ma).Text = b_gtri;
                   }
                   else if (b_ctr is kieu)
                   {
                       (b_ctr as kieu).Text = b_gtri;
                   }
                   else if (b_ctr is nhom)
                   {
                       (b_ctr as nhom).Text = b_gtri;
                   }
                   else if (b_ctr is dao)
                   {
                       (b_ctr as dao).Text = b_gtri;
                   }
                   else if (b_ctr is ngay)
                   {
                       (b_ctr as ngay).Text = b_gtri;
                   }
                   //else if (b_ctr is thang)
                   //{
                   //    (b_ctr as thang).set_Text(b_gtri);
                   //}
                   else if (b_ctr is so)
                   {
                       (b_ctr as so).Text = chuyen.CH_CSO(b_gtri, 5);
                   }
                   else if (b_ctr is nd)
                   {
                       (b_ctr as nd).Text = b_gtri;
                   }
                   else if (b_ctr is DR_nhap)
                   {
                       DR_nhap _nhap = b_ctr as DR_nhap;
                       int num = Fi_DROP_HANG(_nhap, b_gtri);
                       if (num >= 0)
                       {
                           _nhap.SelectedIndex = num;
                       }
                   }
                   else if (b_ctr is HiddenField)
                   {
                       (b_ctr as HiddenField).Value = b_gtri;
                   }
                   else if (b_ctr is Label)
                   {
                       (b_ctr as Label).Text = b_gtri;
                   }
                   else
                   {
                       (b_ctr as TextBox).Text = b_gtri;
                   }
               }
           }

           public static void P_GTRI_TEXT(Control b_f, string b_ten, string b_gtri)
           {
               Control control = Fc_CTR(b_f, b_ten);
               if (control != null)
               {
                   P_GTRI_TEXT(control, b_gtri);
               }
           }
           */

        public static void Msg(Page formPage, string error)
        {
            error = GetError(error);
            if (error != "")
            {
                formPage.ClientScript.RegisterClientScriptBlock(formPage.GetType(), "Display Error", "alert('" + error + "');", true);
            }
        }

        public static void Msg(Page formPage, string nameErr, string error)
        {
            error = GetError(error);
            if (error != "")
            {
                if (nameErr != "")
                {
                    error = error + " " + nameErr;
                }
                formPage.ClientScript.RegisterClientScriptBlock(formPage.GetType(), "Cảnh báo Error", "alert('" + error + "');", true);
            }
        }

        /*
        public static void P_MO(Page b_f, string b_ftk, string b_id)
        {
            string str = "";// Fs_TKHAO(b_ftk);
            string str2 = b_f.ResolveUrl(b_ftk);
            if (str != "")
            {
                string[] strArray = HttpContext.Current.Session["trang"] as string[];
                if (strArray == null)
                {
                    strArray = new string[0];
                }
                int index = -1;
                string str3 = str + ",";
                for (int i = 0; i < strArray.Length; i++)
                {
                    if (strArray[i].IndexOf(str3) == 0)
                    {
                        index = i;
                        break;
                    }
                }
                str3 = str3 + b_f.Title + "," + b_id;
                if (index < 0)
                {
                    mang.P_MO(ref strArray, 1, str3);
                }
                else
                {
                    strArray[index] = str3;
                }
                HttpContext.Current.Session["trang"] = strArray;
                string str4 = "";
                for (int j = 0; j < strArray.Length; j++)
                {
                    str3 = strArray[j].Split(new char[] { ',' })[0];
                    kytu.P_CONG(ref str4, str3);
                }
                str3 = "form_P_MO('" + str2 + "','" + b_f.Title + "," + b_id + "',null);";
                b_f.ClientScript.RegisterClientScriptBlock(b_f.GetType(), "mo", str3, true);
            }
        }

        public static void P_MOI(Control b_f, string b_xoa)
        {
            for (int i = 0; i < b_f.Controls.Count; i++)
            {
                Control control = b_f.Controls[i];
                if (control.Controls.Count > 0)
                {
                    P_MOI(control, b_xoa);
                }
                else if (control is gchu)
                {
                    if (b_xoa.Contains((control as gchu).kt_xoa))
                    {
                        (control as gchu).Text = "";
                    }
                }
                else if (control is ma)
                {
                    if (b_xoa.Contains((control as ma).kt_xoa))
                    {
                        (control as ma).Text = "";
                    }
                }
                else if (control is so)
                {
                    if (b_xoa.Contains((control as so).kt_xoa))
                    {
                        (control as so).Text = "";
                    }
                }
                else if (control is ngay)
                {
                    if (b_xoa.Contains((control as ngay).kt_xoa))
                    {
                        (control as ngay).Text = chuyen.CNG_TRANG();
                    }
                }
              
                else if (control is nd)
                {
                    if (b_xoa.Contains((control as nd).kt_xoa))
                    {
                        (control as nd).Text = "";
                    }
                }
                else if ((control is nhan) && b_xoa.Contains((control as nhan).kt_xoa))
                {
                    (control as nhan).Text = "";
                }
            }
        }

        public static void P_MOI(Control[] a_ctr, string b_xoa)
        {
            for (int i = 0; i < a_ctr.Length; i++)
            {
                P_MOI(a_ctr[i], b_xoa);
            }
        }

        public static void P_NHAN(Page b_f, string b_tkhao)
        {
            P_NHAN(b_f, b_tkhao, false);
        }

        public static void P_NHAN(Page b_f, string b_tkhao, bool b_focus)
        {
            string script = "try {var b_g=window.opener;";
            script = script + "if (b_g==null) b_g=window;";
            script = script + "if (b_g." + b_tkhao + "!=null) {try {b_g." + b_tkhao + ".p_ketqua();} catch(ex){}}";
            if (b_focus)
            {
                script = script + "b_g." + b_tkhao + ".focus();";
            }
            script = script + "} catch(ex){}";
            b_f.ClientScript.RegisterClientScriptBlock(b_f.GetType(), b_tkhao, script, true);
        }

        public static void P_ROW_TEXT(Control b_f, DataRow b_dr)
        {
            DataTable table = b_dr.Table.Clone();
            for (int i = 0; i < table.Columns.Count; i++)
            {
                Control control = Fc_CTR(b_f, table.Columns[i].ColumnName);
                if (Fb_CTR_TB(control))
                {
                    string str;
                    if (b_dr[i] is DateTime)
                    {
                        str = chuyen.NG_CNG(chuyen.OBJ_D(b_dr[i]));
                        if (str == "01/01/3000")
                        {
                            str = "";
                        }
                    }
                    else if ((control is ngay) && ((control as ngay).kieu_luu == ngay.kieu.I))
                    {
                        str = (b_dr[i] is string) ? chuyen.CSO_CNG(chuyen.OBJ_S(b_dr[i])) : chuyen.SO_CNG((int)chuyen.OBJ_N(b_dr[i]));
                        if (str == "01/01/3000")
                        {
                            str = "";
                        }
                    }
                    //else if ((control is thang) && ((control as thang).kieu_luu == thang.kieu.I))
                    //{
                    //    str = chuyen.SO_CTH(chuyen.OBJ_I(b_dr[i]));
                    //}
                    else
                    {
                        str = chuyen.OBJ_S(b_dr[i]);
                    }
                    P_GTRI_TEXT(control, str);
                }
            }
        }

        public static void P_ROW_TEXT(Control b_f, DataRow b_dr, string[] a_cot)
        {
            DataTable table = b_dr.Table.Clone();
            for (int i = 0; i < table.Columns.Count; i++)
            {
                string str = table.Columns[i].ColumnName.ToUpper();
                bool flag = true;
                for (int j = 0; j < a_cot.Length; j++)
                {
                    if (str == a_cot[j].ToUpper())
                    {
                        flag = false;
                        break;
                    }
                }
                if (flag)
                {
                    Control control = Fc_CTR(b_f, str);
                    if (Fb_CTR_TB(control))
                    {
                        if (b_dr[i] is DateTime)
                        {
                            str = chuyen.NG_CNG(chuyen.OBJ_D(b_dr[i]));
                            if (str == "01/01/3000")
                            {
                                str = "";
                            }
                        }
                        else if ((control is ngay) && ((control as ngay).kieu_luu == ngay.kieu.I))
                        {
                            str = (b_dr[i] is string) ? chuyen.CSO_CNG(chuyen.OBJ_S(b_dr[i])) : chuyen.SO_CNG((int)chuyen.OBJ_N(b_dr[i]));
                            if (str == "01/01/3000")
                            {
                                str = "";
                            }
                        }
                        //else if ((control is thang) && ((control as thang).kieu_luu == thang.kieu.I))
                        //{
                        //    str = chuyen.SO_CTH(chuyen.OBJ_I(b_dr[i]));
                        //}
                        else
                        {
                            str = chuyen.OBJ_S(b_dr[i]);
                        }
                        P_GTRI_TEXT(control, str);
                    }
                }
            }
        }

        public static void P_ROW_TEXT(Control b_f, DataRow b_dr, string b_cot)
        {
            DataTable table = b_dr.Table.Clone();
            b_cot = b_cot.ToUpper();
            for (int i = 0; i < table.Columns.Count; i++)
            {
                string str = table.Columns[i].ColumnName.ToUpper();
                if (str != b_cot)
                {
                    Control control = Fc_CTR(b_f, str);
                    if (Fb_CTR_TB(control))
                    {
                        if (b_dr[i] is DateTime)
                        {
                            str = chuyen.NG_CNG(chuyen.OBJ_D(b_dr[i]));
                            if (str == "01/01/3000")
                            {
                                str = "";
                            }
                        }
                        else if ((control is ngay) && ((control as ngay).kieu_luu == ngay.kieu.I))
                        {
                            str = (b_dr[i] is string) ? chuyen.CSO_CNG(chuyen.OBJ_S(b_dr[i])) : chuyen.SO_CNG((int)chuyen.OBJ_N(b_dr[i]));
                            if (str == "01/01/3000")
                            {
                                str = "";
                            }
                        }
                        //else if ((control is thang) && ((control as thang).kieu_luu == thang.kieu.I))
                        //{
                        //    str = chuyen.SO_CTH(chuyen.OBJ_I(b_dr[i]));
                        //}
                        else
                        {
                            str = chuyen.OBJ_S(b_dr[i]);
                        }
                        P_GTRI_TEXT(control, str);
                    }
                }
            }
        }

        public static void P_TABLE_TEXT(Control b_f, DataTable b_dt)
        {
            for (int i = 0; i < b_dt.Rows.Count; i++)
            {
                DataRow row = b_dt.Rows[i];
                Control control = Fc_CTR(b_f, chuyen.OBJ_S(row[0]));
                if (Fb_CTR_TB(control))
                {
                    string str;
                    if (row[1] is DateTime)
                    {
                        str = chuyen.NG_CNG(chuyen.OBJ_D(row[1]));
                    }
                    else if ((control is ngay) && ((control as ngay).kieu_luu == ngay.kieu.I))
                    {
                        str = chuyen.SO_CNG(chuyen.OBJ_I(row[1]));
                    }
                    //else if ((control is thang) && ((control as thang).kieu_luu == thang.kieu.I))
                    //{
                    //    str = chuyen.SO_CTH(chuyen.OBJ_I(row[1]));
                    //}
                    else
                    {
                        str = chuyen.OBJ_S(row[1]);
                    }
                    P_GTRI_TEXT(control, str);
                }
            }
        }

        public static void P_TEXT_ROW(Control b_f, ref DataTable b_dt)
        {
            P_TEXT_ROW(b_f, ref b_dt, "N'", new Control[0]);
        }

        public static void P_TEXT_ROW(Control b_f, ref DataTable b_dt, bool b_all)
        {
            P_TEXT_ROW(b_f, ref b_dt, "N'", new Control[0], b_all);
        }

        public static void P_TEXT_ROW(Control b_f, ref DataTable b_dt, string b_ucd)
        {
            P_TEXT_ROW(b_f, ref b_dt, b_ucd, new Control[0]);
        }

        public static void P_TEXT_ROW(Control b_f, ref DataTable b_dt, Control b_ctr_loai)
        {
            P_TEXT_ROW(b_f, ref b_dt, "N'", b_ctr_loai);
        }

        public static void P_TEXT_ROW(Control b_f, ref DataTable b_dt, string b_ucd, Control[] a_ctr_loai)
        {
            P_TEXT_ROW(b_f, ref b_dt, b_ucd, a_ctr_loai, false);
        }

        public static void P_TEXT_ROW(Control b_f, ref DataTable b_dt, string b_ucd, bool b_all)
        {
            P_TEXT_ROW(b_f, ref b_dt, b_ucd, new Control[0], b_all);
        }

        public static void P_TEXT_ROW(Control b_f, ref DataTable b_dt, string b_ucd, Control b_ctr_loai)
        {
            P_TEXT_ROW(b_f, ref b_dt, b_ucd, new Control[] { b_ctr_loai });
        }

        public static void P_TEXT_ROW(Control b_f, ref DataTable b_dt, Control b_ctr_loai, bool b_all)
        {
            P_TEXT_ROW(b_f, ref b_dt, "N'", b_ctr_loai, b_all);
        }

        public static void P_TEXT_ROW(Control b_f, ref DataTable b_dt, string b_ucd, Control b_ctr_loai, bool b_all)
        {
            P_TEXT_ROW(b_f, ref b_dt, b_ucd, new Control[] { b_ctr_loai }, b_all);
        }

        public static void P_TEXT_ROW(Control b_f, ref DataTable b_dt, string b_ucd, Control[] a_ctr_loai, bool b_all)
        {
            if (b_dt.Rows.Count == 0)
            {
                b_dt.Rows.Add(b_dt.NewRow());
            }
            for (int i = 0; i < b_f.Controls.Count; i++)
            {
                Control control = b_f.Controls[i];
                bool flag = true;
                for (int j = 0; j < a_ctr_loai.Length; j++)
                {
                    string str2 = (a_ctr_loai[j] == null) ? "" : a_ctr_loai[j].ID;
                    if (str2 != "")
                    {
                        if (str2 == control.ID)
                        {
                            flag = false;
                        }
                        else if (Fb_CTR(a_ctr_loai[j], kytu.C_NVL(control.ID)))
                        {
                            flag = false;
                        }
                    }
                }
                if (flag)
                {
                    if (control.Controls.Count > 0)
                    {
                        P_TEXT_ROW(control, ref b_dt, b_ucd, a_ctr_loai, b_all);
                        continue;
                    }
                    if (control is ngay)
                    {
                        ngay ngay = (ngay)control;
                        if (!ngay.nhap && !b_all)
                        {
                            continue;
                        }
                        switch (ngay.kieu_luu)
                        {
                            case ngay.kieu.D:
                                {
                                    bang.P_THEM_COL(ref b_dt, ngay.ID, chuyen.CNG_NG(ngay.Text));
                                    continue;
                                }
                            case ngay.kieu.I:
                                {
                                    bang.P_THEM_COL(ref b_dt, ngay.ID, chuyen.CNG_SO(ngay.Text));
                                    continue;
                                }
                        }
                        bang.P_THEM_COL(ref b_dt, ngay.ID, ngay.Text);
                        continue;
                    }
                    //if (control is thang)
                    //{
                    //    thang thang = (thang)control;
                    //    if (thang.nhap || b_all)
                    //    {
                    //        if (thang.kieu_luu == thang.kieu.I)
                    //        {
                    //            bang.P_THEM_COL(ref b_dt, thang.ID, chuyen.CTH_SO(thang.get_Text()));
                    //        }
                    //        else
                    //        {
                    //            bang.P_THEM_COL(ref b_dt, thang.ID, thang.get_Text());
                    //        }
                    //    }
                    //}
                    //else 
                    if (control is so)
                    {
                        so so = (so)control;
                        if (so.nhap || b_all)
                        {
                            bang.P_THEM_COL(ref b_dt, so.ID, chuyen.CSO_SO(so.Text));
                        }
                    }
                    else
                    {
                        string str;
                        if (control is ma)
                        {
                            ma ma = (ma)control;
                            if (ma.nhap || b_all)
                            {
                                str = kytu.C_NVL(ma.Text).Replace("'", "");
                                if (ma.kieu_unicode && (str != ""))
                                {
                                    str = b_ucd + str;
                                }
                                bang.P_THEM_COL(ref b_dt, ma.ID, str);
                            }
                        }
                        else if (control is nhan)
                        {
                            nhan nhan = (nhan)control;
                            if (nhan.nhap || b_all)
                            {
                                str = kytu.C_NVL(nhan.Text).Replace("'", "");
                                bang.P_THEM_COL(ref b_dt, nhan.ID, str);
                            }
                        }
                        else if (control is kieu)
                        {
                            kieu kieu = (kieu)control;
                            if (kieu.nhap || b_all)
                            {
                                str = kytu.C_NVL(kieu.Text).Replace("'", "");
                                bang.P_THEM_COL(ref b_dt, kieu.ID, str);
                            }
                        }
                        else if (control is nhom)
                        {
                            nhom nhom = (nhom)control;
                            if (nhom.nhap || b_all)
                            {
                                str = kytu.C_NVL(nhom.Text).Replace("'", "");
                                if (nhom.kieu_unicode && (str != ""))
                                {
                                    str = b_ucd + str;
                                }
                                bang.P_THEM_COL(ref b_dt, nhom.ID, str);
                            }
                        }
                        else if (control is dao)
                        {
                            dao dao = (dao)control;
                            if (dao.nhap || b_all)
                            {
                                str = kytu.C_NVL(dao.Text).Replace("'", "");
                                bang.P_THEM_COL(ref b_dt, dao.ID, str);
                            }
                        }
                        else if (control is nd)
                        {
                            nd nd = (nd)control;
                            if (nd.nhap || b_all)
                            {
                                str = kytu.C_NVL(nd.Text).Replace("'", "");
                                if (str != "")
                                {
                                    str = b_ucd + str;
                                }
                                bang.P_THEM_COL(ref b_dt, nd.ID, str);
                            }
                        }
                        else if (control is DR_nhap)
                        {
                            DR_nhap _nhap = (DR_nhap)control;
                            if ( b_all)
                            {
                                object obj2 = Fobj_DROP(_nhap);
                                str = chuyen.OBJ_S(obj2);
                                if (str != "")
                                {
                                    obj2 = b_ucd + str;
                                }
                                bang.P_THEM_COL(ref b_dt, _nhap.ID, obj2);
                            }
                        }
                    }
                }
            }
        }

        public static void P_THEM_HIFI(Control b_f)
        {
            for (int i = 0; i < b_f.Controls.Count; i++)
            {
                Control control = b_f.Controls[i];
                if (control.Controls.Count != 0)
                {
                    P_THEM_HIFI(control);
                }
                else if (control is dao)
                {
                    string str = control.ID + "_hifi";
                    if (((HiddenField)Fc_CTR(control.Parent, str)) == null)
                    {
                        HiddenField child = new HiddenField
                        {
                            ID = str,
                            Value = (control as dao).Text
                        };
                        control.Parent.Controls.Add(child);
                    }
                }
            }
        }

        public static void P_UPa_DAT(Control b_f, string b_ten)
        {
            string[] strArray = b_ten.Split(new char[] { ',' });
            for (int i = 0; i < strArray.Length; i++)
            {
                Control control = Fc_CTR(b_f, strArray[i]);
                if ((control != null) && (control is UpdatePanel))
                {
                    UpdatePanel panel = (UpdatePanel)control;
                    if (panel.UpdateMode == UpdatePanelUpdateMode.Conditional)
                    {
                        panel.Update();
                    }
                }
            }
        }

        public static void P_UPa_MOI(Control b_f, string b_loai)
        {
            string[] strArray = b_loai.Split(new char[] { ',' });
            for (int i = 0; i < b_f.Controls.Count; i++)
            {
                Control control = b_f.Controls[i];
                if (control is UpdatePanel)
                {
                    UpdatePanel panel = (UpdatePanel)control;
                    if (panel.UpdateMode != UpdatePanelUpdateMode.Conditional)
                    {
                        continue;
                    }
                    bool flag = true;
                    for (int j = 0; j < strArray.Length; j++)
                    {
                        if (strArray[j] == panel.ID)
                        {
                            flag = false;
                            break;
                        }
                    }
                    if (flag)
                    {
                        panel.Update();
                    }
                    continue;
                }
                if (control.Controls.Count > 0)
                {
                    P_UPa_MOI(control, b_loai);
                }
            }
        }

        public static void P_XOA_CTR(HtmlTableCell b_cell)
        {
            try
            {
                se.P_CTR_XOA(b_cell.Page.Title);
                b_cell.Controls.Clear();
            }
            catch
            {
            }
        }

        public static void P_XOA_CTR(HtmlTableCell b_cell, string b_ten)
        {
            Control control = Fc_CTR(b_cell, b_ten);
            if (control != null)
            {
                se.P_CTR_XOA(b_cell.Page.Title, b_ten);
                b_cell.Controls.Remove(control);
            }
        }
         * */
    }
}

